package cn.com.huzo.repository.tech.impl;

import cn.com.huzo.model.entities.tech.CostForecastHeaderEntity;
import huzofw.repository.impl.GenericRepositoryImpl;
import huzofw.repository.impl.MyBatisDaoUtils;
import cn.com.huzo.repository.tech.CostForecastHeaderRepository;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;

/**
 * 产品成本预测明细表数据访问对象。
 *
 * @author 范学春
 */
@Repository("CostForecastHeaderRepository")
public class CostForecastHeaderRepositoryImpl extends GenericRepositoryImpl<CostForecastHeaderEntity, Long>
        implements CostForecastHeaderRepository {

    private final String namespace = "cn.com.huzo.repository.tech.CostForecastHeaderRepository";

    /**
     * 构造函数,设置the entity to CostForecastHeaderRepositoryImpl.class.
     */
    public CostForecastHeaderRepositoryImpl() {
        super(CostForecastHeaderEntity.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public CostForecastHeaderEntity fetchByKey(Long headerId, Long currentUserId, Long workFlowId) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("CurrentUserId", currentUserId);
        criterion.put("WorkFlowId", workFlowId);

        return getSqlSession().selectOne(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchById"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer fetchForCount(Map<String, Object> criterion) {
        return getSqlSession().selectOne(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForCount"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<CostForecastHeaderEntity> fetchForPage(Map<String, Object> criterion) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForPage"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Long insert(CostForecastHeaderEntity instance) {
        // 影响的行数
        getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "insert"), instance);

        // 返回出入后的记录ID
        return instance.getHeaderId();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer update(CostForecastHeaderEntity instance) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "update"), instance);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer updateLastUpdatedDate(Long headerId) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "updateLastUpdatedDate"), headerId);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer delete(Long id) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "delete"), id);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String fetchNewBillNo() {
        return getSqlSession().selectOne(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchNewBillNo"));
    }
}
